/**
 *
 * Copyright 2015 RSVP Technologies Inc. All rights reserved.
 * test.java
 *
 */
package com.gfinal.algorithm;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.InvalidPropertiesFormatException;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Gao Yudong (gyd@nbicc.com)
 * @date 2015-3-4
 */
public class test {
	public static void main(String[] args) throws FileNotFoundException,
			IOException {
		// List<Integer> list = new ArrayList<Integer>();
		// list.add(9);
		// list.add(4);
		// list.add(2);
		// list.add(8);
		// list.add(5);
		// list.add(9);
		// list.add(7);
		// list.add(3);
		// list.add(1);
		//
		// list.remove(new Integer(9));
		// while(list.remove(new Integer(9)));
		//
		// Collections.sort(list, new Comparator<Integer>() {
		//
		// @Override
		// public int compare(Integer o1, Integer o2) {
		// if(o1 < o2) return -1;
		// else if(o1 == o2) return 0;
		// else return 1;
		// }
		//
		// });
		//
		// int index = Collections.binarySearch(list, 7, new
		// Comparator<Integer>() {
		//
		// @Override
		// public int compare(Integer o1, Integer o2) {
		// if(o1 < o2) return -1;
		// else if(o1 == o2) return 0;
		// else return 1;
		// }
		//
		// });
		//
		// System.out.print(index);
		//
		// Iterator it = list.iterator();
		// while(it.hasNext()) {
		// System.out.print(it.next());
		// }
		// Properties props = new Properties();
		// props.load(new FileInputStream("prop.properties"));
		// String username = props.getProperty("username");
		// String password = props.getProperty("password");

		// ScheduledThreadPoolExecutor exec = new
		// ScheduledThreadPoolExecutor(1);
		// exec.scheduleAtFixedRate(new Runnable() {
		//
		// @Override
		// public void run() {
		// Date date = new Date();
		// System.out.println(date.getHours() + "-" + date.getMinutes() + "-" +
		// date.getSeconds());
		// }
		//
		// }, 3000, 3000, TimeUnit.MILLISECONDS);

		// final ThreadPoolExecutor exec = (ThreadPoolExecutor)
		// Executors.newCachedThreadPool();
		final ThreadPoolExecutor exec = (ThreadPoolExecutor) Executors
				.newFixedThreadPool(300);

		// Runnable command = new Runnable() {
		//
		// @Override
		// public void run() {
		// System.out.println(Thread.currentThread().getName() + ":" +
		// exec.getActiveCount());
		// try {
		// Thread.sleep(1000);
		// } catch (InterruptedException e) {
		//
		// }
		// }
		//
		// };
		// for(int i = 0; i < 300; i++) {
		// exec.execute(command);
		// System.out.println(Thread.currentThread().getName());
		// }
		//
		// exec.shutdownNow();

		Callable<Integer> task = new Callable<Integer>() {

			@Override
			public Integer call() throws Exception {
				Thread.sleep(1000);
				return 999;
			}

		};
		Future<Integer> future = exec.submit(task);
		future.cancel(false);
		try {
			if (!future.isCancelled())
				System.out.println(future.get());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("finish");
	}
}
